package io.xiaojl.xj2ee.modules.sys.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import io.xiaojl.xj2ee.common.kit.PageWrapper;
import io.xiaojl.xj2ee.kit.JpaPageKit;
import io.xiaojl.xj2ee.modules.sys.entity.SysDictEntity;
import io.xiaojl.xj2ee.modules.sys.repository.SysDictRepository;
import io.xiaojl.xj2ee.modules.sys.service.SysDictService;


@Service("sysDictService")
public class SysDictServiceImpl implements SysDictService {
	@Autowired
	private SysDictRepository sysDictRepository;
    @Override
    public PageWrapper<SysDictEntity> queryPage(Map<String, Object> params) {
    	PageWrapper<SysDictEntity> pw = new PageWrapper<>(params);
    	Pageable pageable = JpaPageKit.getPageable(pw);
		Page<SysDictEntity> page = sysDictRepository.findAll(pageable);
		pw.setList(page.getContent());
		pw.setTotalCount(Integer.parseInt(page.getTotalElements()+""));
		pw.setTotalPage(page.getTotalPages());
		
        return pw;
    }
	@Override
	public SysDictEntity selectById(Long id) {
		return sysDictRepository.getOne(id);
	}
	@Override
	public int insert(SysDictEntity dict) {
		sysDictRepository.save(dict);
		return 1;
	}
	@Override
	public int updateById(SysDictEntity dict) {
		sysDictRepository.save(dict);
		return 1;
	}
	@Override
	public int deleteBatchIds(Long[] ids) {
		List<SysDictEntity> list = sysDictRepository.findAllById(Arrays.asList(ids));
		sysDictRepository.deleteAll(list);
		return list.size();
	}

}
